SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [GOOGLECODERS].[Beneficiarios](
	[IdBeneficiario] [int]  NOT NULL Identity(1,1),
	[RazonSocial] [varchar](255) COLLATE Modern_Spanish_CI_AS NOT NULL,
	[DirCalle] [varchar](255) COLLATE Modern_Spanish_CI_AS NOT NULL,
	[DirNro] [int] NOT NULL,
	[DirPiso] [int],
	[DirDepto] [varchar](2) COLLATE Modern_Spanish_CI_AS NULL,
	[idRubro] [int] NOT NULL,
    [Habilitado] [bit] NOT NULL,
	UNIQUE (RazonSocial)
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF

ALTER TABLE [GOOGLECODERS].[Beneficiarios] ADD
	CONSTRAINT PK_tBeneficiarios PRIMARY KEY (IdBeneficiario),
	CONSTRAINT FK_rubro FOREIGN KEY (idRubro)
		REFERENCES [GOOGLECODERS].[Rubros] (IdRubro);
GO

INSERT INTO [GOOGLECODERS].[Beneficiarios]
           ( [RazonSocial]
            ,[DirCalle]
            ,[DirNro]
            ,[DirPiso]
            ,[DirDepto]
			,[idRubro]
            ,[Habilitado] )  
	
SELECT DISTINCT 
		[BENEFICIARIO_NOMBRE]
      ,[BENEFICIARIO_CALLE]
      ,[BENEFICIARIO_NRO]
      ,[BENEFICIARIO_PISO]
	  ,[BENEFICIARIO_DEPTO]
	  ,[BENEFICIARIO_RUBRO_CODIGO]
      , 1
  FROM [GD2C2011].[gd_eschema].[Maestra]
WHERE BENEFICIARIO_NOMBRE IS NOT NULL
